/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MenuPrincipal.java
 *
 * Created on Nov 17, 2010, 10:20:35 AM
 */
package br.com.tbp.gui;

import br.com.tbp.controle.ControleRelatorio;
import br.com.tbp.exception.PersistenciaException;
import br.com.tbp.model.domain.Boc;
import br.com.tbp.model.domain.Consultor;
import br.com.tbp.model.domain.Empresa;
import br.com.tbp.model.domain.Pedido;
import br.com.tbp.model.domain.Produto;
import br.com.tbp.model.domain.Supervisor;
import br.com.tbp.model.domain.Usuario;
import br.com.tbp.utils.DateUtils;
import br.com.tbp.utils.ImageUtils;
import com.towel.swing.img.JImagePanel;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.UIManager;
import org.jdesktop.swingx.JXHyperlink;

/**
 *
 * @author Diego Freire
 */
public class MenuPrincipal extends javax.swing.JFrame {

    private JImagePanel imagem_rodape;
    private LoginDialog loginDialog;
    private LogoutAction logoutAction;

    public MenuPrincipal(LoginDialog login) {
        initComponents();
        setSize(1024, 700);
        setLocationRelativeTo(null);
        this.loginDialog = login;
        setIconImage(ImageUtils.createIcon("sistema.png").getImage());
        carregaCabecalho();
        carregaRodape();
        ativacaoMenuItem.setVisible(false);
        //ajudaCustoMenuItem.setEnabled(false);
        //relatorioAjudaCustoMenuItem.setEnabled(false);
        //setIconImage(ImageUtils.createIcon("marca_acriel.png").getImage());
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        usuarioPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        bemVindoLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        dataLabel = new javax.swing.JLabel();
        logoutPanel = new javax.swing.JPanel();
        artePanel = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        acrielLabel = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        arquivoMenu = new javax.swing.JMenu();
        ferramentasMenu = new javax.swing.JMenu();
        calculadoraMenuItem = new javax.swing.JMenuItem();
        jSeparator6 = new javax.swing.JPopupMenu.Separator();
        logoutMenuItem = new javax.swing.JMenuItem();
        sairMenuItem = new javax.swing.JMenuItem();
        cadastroMenu = new javax.swing.JMenu();
        empresaMenu = new javax.swing.JMenu();
        addEmpresa = new javax.swing.JMenuItem();
        pesquisarEmpresaMenuItem = new javax.swing.JMenuItem();
        pedidoMenu = new javax.swing.JMenu();
        addPedido = new javax.swing.JMenuItem();
        pesquisarPedidoMenuItem = new javax.swing.JMenuItem();
        separador1 = new javax.swing.JPopupMenu.Separator();
        consultorMenu = new javax.swing.JMenu();
        addConsultor = new javax.swing.JMenuItem();
        pesquisarConsultorMenuItem = new javax.swing.JMenuItem();
        produtoMenu = new javax.swing.JMenu();
        cadastrarProdutoMenuItem = new javax.swing.JMenuItem();
        pesquisarProdutoMenuItem = new javax.swing.JMenuItem();
        bocMenu = new javax.swing.JMenu();
        addBoc = new javax.swing.JMenuItem();
        pesquisarBocMenuItem = new javax.swing.JMenuItem();
        supervisorMenu = new javax.swing.JMenu();
        addSupervisor = new javax.swing.JMenuItem();
        pesquisarSupervisorMenuItem = new javax.swing.JMenuItem();
        ativacaoMenuItem = new javax.swing.JMenuItem();
        financeiroMenu = new javax.swing.JMenu();
        ajudaCustoMenuItem = new javax.swing.JMenuItem();
        funilVendaMenu = new javax.swing.JMenu();
        pesquisarVisitasMenuItem = new javax.swing.JMenuItem();
        relatorioMenu = new javax.swing.JMenu();
        relatorioConsultoresMenuItem = new javax.swing.JMenuItem();
        relatorioLinhasMenuItem = new javax.swing.JMenuItem();
        rankingDePedidosMenuItem = new javax.swing.JMenuItem();
        rankingEntradaDeProdutosMenuItem = new javax.swing.JMenuItem();
        produtividadeMenuItem = new javax.swing.JMenuItem();
        relatorioBocMenuItem = new javax.swing.JMenuItem();
        relatorioAniversariantesMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        relatorioVisitasMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        relatorioFinanceiroMenu = new javax.swing.JMenu();
        relatorioAjudaCustoMenuItem = new javax.swing.JMenuItem();
        configuracaoMenu = new javax.swing.JMenu();
        usuarioMenu = new javax.swing.JMenu();
        novoUsuarioMenuItem = new javax.swing.JMenuItem();
        listarUsuariosMenuItem = new javax.swing.JMenuItem();
        trocarSenhaMenuItem = new javax.swing.JMenuItem();
        ajudaMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Acriel Consultoria - Agente Business");

        usuarioPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(195, 223, 251)));
        usuarioPanel.setLayout(new java.awt.GridLayout(3, 0));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        bemVindoLabel.setText("Bem-vindo Usuário, seu último acesso foi em: 18/01/2011 20:50");
        jPanel1.add(bemVindoLabel);

        usuarioPanel.add(jPanel1);

        jPanel2.setBackground(new java.awt.Color(195, 223, 251));
        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        dataLabel.setText("Hoje é Terça-feira, 18/01/2011");
        jPanel2.add(dataLabel);

        usuarioPanel.add(jPanel2);

        logoutPanel.setBackground(new java.awt.Color(255, 255, 255));
        logoutPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
        usuarioPanel.add(logoutPanel);

        getContentPane().add(usuarioPanel, java.awt.BorderLayout.PAGE_START);

        artePanel.setPreferredSize(new java.awt.Dimension(1024, 112));
        artePanel.setLayout(new java.awt.BorderLayout());
        getContentPane().add(artePanel, java.awt.BorderLayout.PAGE_END);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setLayout(new java.awt.BorderLayout());

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        acrielLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/acriel-marca.png"))); // NOI18N
        acrielLabel.setToolTipText("www.acrielconsultoria.com.br");
        acrielLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        acrielLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                acrielLabelMouseClicked(evt);
            }
        });
        jPanel5.add(acrielLabel);

        jPanel4.add(jPanel5, java.awt.BorderLayout.PAGE_END);

        getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);

        arquivoMenu.setText("Arquivo");

        ferramentasMenu.setText("Ferramentas");

        calculadoraMenuItem.setText("Calculadora");
        calculadoraMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calculadoraMenuItemActionPerformed(evt);
            }
        });
        ferramentasMenu.add(calculadoraMenuItem);

        arquivoMenu.add(ferramentasMenu);
        arquivoMenu.add(jSeparator6);

        logoutMenuItem.setText("Logout");
        arquivoMenu.add(logoutMenuItem);

        sairMenuItem.setText("Sair");
        sairMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairMenuItemActionPerformed(evt);
            }
        });
        arquivoMenu.add(sairMenuItem);

        menuBar.add(arquivoMenu);

        cadastroMenu.setText("Cadastro");

        empresaMenu.setText("Empresa");
        empresaMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/clientes16.png"))); // NOI18N

        addEmpresa.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0));
        addEmpresa.setText("Nova");
        addEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addEmpresaActionPerformed(evt);
            }
        });
        empresaMenu.add(addEmpresa);

        pesquisarEmpresaMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0));
        pesquisarEmpresaMenuItem.setText("Pesquisar...");
        pesquisarEmpresaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesquisarEmpresaMenuItemActionPerformed(evt);
            }
        });
        empresaMenu.add(pesquisarEmpresaMenuItem);

        cadastroMenu.add(empresaMenu);

        pedidoMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/vendas16.png"))); // NOI18N
        pedidoMenu.setText("Pedido");

        addPedido.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        addPedido.setText("Novo");
        addPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPedidoActionPerformed(evt);
            }
        });
        pedidoMenu.add(addPedido);

        pesquisarPedidoMenuItem.setText("Pesquisar");
        pesquisarPedidoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
        pesquisarPedidoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesquisarPedidoMenuItemActionPerformed(evt);
            }
        });
        pedidoMenu.add(pesquisarPedidoMenuItem);

        cadastroMenu.add(pedidoMenu);
        cadastroMenu.add(separador1);

        consultorMenu.setText("Consultor");
        consultorMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/consultor16.png"))); // NOI18N

        addConsultor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, 0));
        addConsultor.setText("Novo");
        addConsultor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addConsultorActionPerformed(evt);
            }
        });
        consultorMenu.add(addConsultor);

        pesquisarConsultorMenuItem.setText("Pesquisar...");
        pesquisarConsultorMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesquisarConsultorMenuItemActionPerformed(evt);
            }
        });
        consultorMenu.add(pesquisarConsultorMenuItem);

        cadastroMenu.add(consultorMenu);

        produtoMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/phone16.png"))); // NOI18N
        produtoMenu.setText("Produto");

        cadastrarProdutoMenuItem.setText("Novo");
        cadastrarProdutoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastrarProdutoMenuItemActionPerformed(evt);
            }
        });
        produtoMenu.add(cadastrarProdutoMenuItem);

        pesquisarProdutoMenuItem.setText("Pesquisar...");
        pesquisarProdutoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesquisarProdutoMenuItemActionPerformed(evt);
            }
        });
        produtoMenu.add(pesquisarProdutoMenuItem);

        cadastroMenu.add(produtoMenu);

        bocMenu.setText("Boc");
        bocMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/shield_16.png"))); // NOI18N

        addBoc.setText("Novo");
        addBoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addBocActionPerformed(evt);
            }
        });
        bocMenu.add(addBoc);

        pesquisarBocMenuItem.setText("Pesquisar...");
        pesquisarBocMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesquisarBocMenuItemActionPerformed(evt);
            }
        });
        bocMenu.add(pesquisarBocMenuItem);

        cadastroMenu.add(bocMenu);

        supervisorMenu.setText("Supervisor");
        supervisorMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/cadeira_16.png"))); // NOI18N

        addSupervisor.setText("Novo");
        addSupervisor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addSupervisorActionPerformed(evt);
            }
        });
        supervisorMenu.add(addSupervisor);

        pesquisarSupervisorMenuItem.setText("Pesquisar...");
        pesquisarSupervisorMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesquisarSupervisorMenuItemActionPerformed(evt);
            }
        });
        supervisorMenu.add(pesquisarSupervisorMenuItem);

        cadastroMenu.add(supervisorMenu);

        ativacaoMenuItem.setText("Ativação de Entrantes");
        ativacaoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ativacaoMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(ativacaoMenuItem);

        menuBar.add(cadastroMenu);

        financeiroMenu.setText("Financeiro");

        ajudaCustoMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/help16x16.png"))); // NOI18N
        ajudaCustoMenuItem.setText("Ajuda de Custo");
        ajudaCustoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ajudaCustoMenuItemActionPerformed(evt);
            }
        });
        financeiroMenu.add(ajudaCustoMenuItem);

        menuBar.add(financeiroMenu);

        funilVendaMenu.setText("Funil de Vendas");

        pesquisarVisitasMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F7, 0));
        pesquisarVisitasMenuItem.setText("Pesquisar Visitas");
        pesquisarVisitasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesquisarVisitasMenuItemActionPerformed(evt);
            }
        });
        funilVendaMenu.add(pesquisarVisitasMenuItem);

        menuBar.add(funilVendaMenu);

        relatorioMenu.setText("Relatório");

        relatorioConsultoresMenuItem.setText("Consultores");
        relatorioConsultoresMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                relatorioConsultoresMenuItemActionPerformed(evt);
            }
        });
        relatorioMenu.add(relatorioConsultoresMenuItem);

        relatorioLinhasMenuItem.setText("Entrada de Linhas");
        relatorioLinhasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                relatorioLinhasMenuItemActionPerformed(evt);
            }
        });
        relatorioMenu.add(relatorioLinhasMenuItem);

        rankingDePedidosMenuItem.setText("Ranking de Pedidos");
        rankingDePedidosMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rankingDePedidosMenuItemActionPerformed(evt);
            }
        });
        relatorioMenu.add(rankingDePedidosMenuItem);

        rankingEntradaDeProdutosMenuItem.setText("Ranking de Entrada de Produtos");
        rankingEntradaDeProdutosMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rankingEntradaDeProdutosMenuItemActionPerformed(evt);
            }
        });
        relatorioMenu.add(rankingEntradaDeProdutosMenuItem);

        produtividadeMenuItem.setText("Produtividade");
        produtividadeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                produtividadeMenuItemActionPerformed(evt);
            }
        });
        relatorioMenu.add(produtividadeMenuItem);

        relatorioBocMenuItem.setText("BOC");
        relatorioBocMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                relatorioBocMenuItemActionPerformed(evt);
            }
        });
        relatorioMenu.add(relatorioBocMenuItem);

        relatorioAniversariantesMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/bolo16x16.png"))); // NOI18N
        relatorioAniversariantesMenuItem.setText("Aniversariantes");
        relatorioAniversariantesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                relatorioAniversariantesMenuItemActionPerformed(evt);
            }
        });
        relatorioMenu.add(relatorioAniversariantesMenuItem);
        relatorioMenu.add(jSeparator1);

        relatorioVisitasMenuItem.setText("Visitas");
        relatorioVisitasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                relatorioVisitasMenuItemActionPerformed(evt);
            }
        });
        relatorioMenu.add(relatorioVisitasMenuItem);
        relatorioMenu.add(jSeparator2);

        relatorioFinanceiroMenu.setText("Financeiro");

        relatorioAjudaCustoMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/help16x16.png"))); // NOI18N
        relatorioAjudaCustoMenuItem.setText("Ajuda de Custo");
        relatorioAjudaCustoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                relatorioAjudaCustoMenuItemActionPerformed(evt);
            }
        });
        relatorioFinanceiroMenu.add(relatorioAjudaCustoMenuItem);

        relatorioMenu.add(relatorioFinanceiroMenu);

        menuBar.add(relatorioMenu);

        configuracaoMenu.setText("Configuração");

        usuarioMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/chave16.png"))); // NOI18N
        usuarioMenu.setText("Usuário");

        novoUsuarioMenuItem.setText("Novo");
        novoUsuarioMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novoUsuarioMenuItemActionPerformed(evt);
            }
        });
        usuarioMenu.add(novoUsuarioMenuItem);

        listarUsuariosMenuItem.setText("Pesquisar...");
        listarUsuariosMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listarUsuariosMenuItemActionPerformed(evt);
            }
        });
        usuarioMenu.add(listarUsuariosMenuItem);

        configuracaoMenu.add(usuarioMenu);

        trocarSenhaMenuItem.setText("Trocar Senha");
        trocarSenhaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                trocarSenhaMenuItemActionPerformed(evt);
            }
        });
        configuracaoMenu.add(trocarSenhaMenuItem);

        menuBar.add(configuracaoMenu);

        ajudaMenu.setText("Ajuda");

        aboutMenuItem.setText("Sobre");
        aboutMenuItem.setEnabled(false);
        ajudaMenu.add(aboutMenuItem);

        menuBar.add(ajudaMenu);

        setJMenuBar(menuBar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addEmpresaActionPerformed
        EmpresaDialog dialog = new EmpresaDialog(this, "TBP - Empresa", true);
        dialog.setEmpresa(new Empresa());
        dialog.setNovaEmpresa(true);
        dialog.setVisible(true);
    }//GEN-LAST:event_addEmpresaActionPerformed

    private void addConsultorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addConsultorActionPerformed
        ConsultorDialog dialog = new ConsultorDialog(this, "TBP - Consultor", true);
        dialog.setConsultor(new Consultor());
        dialog.setNovoConsultor(true);
        dialog.setVisible(true);
    }//GEN-LAST:event_addConsultorActionPerformed

    private void addPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPedidoActionPerformed
        //PedidoDialog dialog = new PedidoDialog(this, "TBP - Pedido", true);
        PedidoDialog dialog = new PedidoDialog(this, "TBP - Pedido", true);
        dialog.setNovoPedido(true);
        dialog.setPedido(new Pedido());
        dialog.setVisible(true);
    }//GEN-LAST:event_addPedidoActionPerformed

    private void calculadoraMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculadoraMenuItemActionPerformed
        try {
            Runtime.getRuntime().exec("calc.exe");
        } catch (IOException ioex) {
            return;
        }
}//GEN-LAST:event_calculadoraMenuItemActionPerformed

    private void sairMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairMenuItemActionPerformed
        System.exit(0);
}//GEN-LAST:event_sairMenuItemActionPerformed

    private void pesquisarConsultorMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesquisarConsultorMenuItemActionPerformed
        ConsultoresDialog dialog = new ConsultoresDialog(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_pesquisarConsultorMenuItemActionPerformed

    private void pesquisarEmpresaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesquisarEmpresaMenuItemActionPerformed
        //EmpresasDialog dialog = new EmpresasDialog(this, true);
        EmpresasPaginadaDialog dialog = new EmpresasPaginadaDialog(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_pesquisarEmpresaMenuItemActionPerformed

    private void pesquisarProdutoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesquisarProdutoMenuItemActionPerformed
        ProdutosDialog dialog = new ProdutosDialog(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_pesquisarProdutoMenuItemActionPerformed

    private void cadastrarProdutoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastrarProdutoMenuItemActionPerformed
        ProdutoDialog dialog = new ProdutoDialog(this, "TBP - Produto", true);
        dialog.setProduto(new Produto());
        dialog.setNovoProduto(true);
        dialog.setVisible(true);
    }//GEN-LAST:event_cadastrarProdutoMenuItemActionPerformed

    private void acrielLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_acrielLabelMouseClicked
        String acriel = acrielLabel.getToolTipText();
        Desktop d = Desktop.getDesktop();
        if (Desktop.isDesktopSupported()) {
            try {
                d.browse(new URI(acriel));
            } catch (URISyntaxException ex) {
                return;
            } catch (IOException ioex) {
                return;
            }
        }
    }//GEN-LAST:event_acrielLabelMouseClicked

    private void pesquisarPedidoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesquisarPedidoMenuItemActionPerformed
        PedidosDialog dialog = new PedidosDialog(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_pesquisarPedidoMenuItemActionPerformed

    private void novoUsuarioMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoUsuarioMenuItemActionPerformed
        UsuarioDialog dialog = new UsuarioDialog(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_novoUsuarioMenuItemActionPerformed

    private void listarUsuariosMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listarUsuariosMenuItemActionPerformed
        UsuariosDialog dialog = new UsuariosDialog(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_listarUsuariosMenuItemActionPerformed

    private void trocarSenhaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trocarSenhaMenuItemActionPerformed
        TrocarSenhaDialog dialog = new TrocarSenhaDialog(this, true,
                loginDialog.getUsuarioSessao().getUsuarioId());
        dialog.setVisible(true);
    }//GEN-LAST:event_trocarSenhaMenuItemActionPerformed

    private void relatorioConsultoresMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relatorioConsultoresMenuItemActionPerformed
        try {
            ControleRelatorio.consultores();
        } catch (PersistenciaException pex) {
            System.out.println(pex.getMessage());
        }
    }//GEN-LAST:event_relatorioConsultoresMenuItemActionPerformed

    private void relatorioLinhasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relatorioLinhasMenuItemActionPerformed
        RelatorioDeLinhasDialog dialog = new RelatorioDeLinhasDialog(this, false);
        dialog.setVisible(true);
    }//GEN-LAST:event_relatorioLinhasMenuItemActionPerformed

    private void rankingDePedidosMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rankingDePedidosMenuItemActionPerformed
        RelatorioRankingDePedidosDialog dialog = new RelatorioRankingDePedidosDialog(this, false);
        dialog.setVisible(true);
    }//GEN-LAST:event_rankingDePedidosMenuItemActionPerformed

    private void rankingEntradaDeProdutosMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rankingEntradaDeProdutosMenuItemActionPerformed
        RelatorioRankingEntradaDeProdutosDialog dialog = new RelatorioRankingEntradaDeProdutosDialog(this, false);
        dialog.setVisible(true);
    }//GEN-LAST:event_rankingEntradaDeProdutosMenuItemActionPerformed

    private void produtividadeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_produtividadeMenuItemActionPerformed
        RelatorioProdutividadeDialog dialog = new RelatorioProdutividadeDialog(this, false);
        dialog.setVisible(true);
    }//GEN-LAST:event_produtividadeMenuItemActionPerformed

    private void addBocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBocActionPerformed
        BocDialog dialog = new BocDialog(this, "TBP - Boc", true);
        dialog.setBoc(new Boc());
        dialog.setNovoBoc(true);
        dialog.setVisible(true);
    }//GEN-LAST:event_addBocActionPerformed

    private void pesquisarBocMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesquisarBocMenuItemActionPerformed
        BocsDialog dialog = new BocsDialog(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_pesquisarBocMenuItemActionPerformed

    private void addSupervisorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addSupervisorActionPerformed
        SupervisorDialog dialog = new SupervisorDialog(this, "TBP - Supervisor", true);
        dialog.setSupervisor(new Supervisor());
        dialog.setNovoSupervisor(true);
        dialog.setVisible(true);
    }//GEN-LAST:event_addSupervisorActionPerformed

    private void pesquisarSupervisorMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesquisarSupervisorMenuItemActionPerformed
        SupervisoresDialog dialog = new SupervisoresDialog(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_pesquisarSupervisorMenuItemActionPerformed

    private void relatorioBocMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relatorioBocMenuItemActionPerformed
        RelatorioBocDialog dialog = new RelatorioBocDialog(this, false);
        dialog.setVisible(true);
    }//GEN-LAST:event_relatorioBocMenuItemActionPerformed

    private void ativacaoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ativacaoMenuItemActionPerformed
        AtivacaoEntrantesFrame frame = new AtivacaoEntrantesFrame("TBP - Ativação de Entrantes");
        frame.setVisible(true);
    }//GEN-LAST:event_ativacaoMenuItemActionPerformed

    private void relatorioAniversariantesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relatorioAniversariantesMenuItemActionPerformed
        RelatorioAniversariantesDialog dialog = new RelatorioAniversariantesDialog(this, false);
        dialog.setVisible(true);
    }//GEN-LAST:event_relatorioAniversariantesMenuItemActionPerformed

    private void ajudaCustoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ajudaCustoMenuItemActionPerformed
        AjudaCustoFrame dialog = new AjudaCustoFrame("TBP - Ajuda de Custo");
        dialog.setVisible(true);
    }//GEN-LAST:event_ajudaCustoMenuItemActionPerformed

    private void relatorioAjudaCustoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relatorioAjudaCustoMenuItemActionPerformed
        RelatorioAjudaCustoDialog dialog = new RelatorioAjudaCustoDialog(this, false);
        dialog.setVisible(true);
    }//GEN-LAST:event_relatorioAjudaCustoMenuItemActionPerformed

    private void pesquisarVisitasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesquisarVisitasMenuItemActionPerformed
        VisitasDialog dialog = new VisitasDialog(new javax.swing.JFrame(), true, null);
        dialog.setVisible(true);
}//GEN-LAST:event_pesquisarVisitasMenuItemActionPerformed

    private void relatorioVisitasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relatorioVisitasMenuItemActionPerformed
        RelatorioVisitaDialog dialog = new RelatorioVisitaDialog(this, true);
        dialog.setVisible(true);
}//GEN-LAST:event_relatorioVisitasMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        UIManager.put("swing.boldMetal", Boolean.FALSE);
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new MenuPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JLabel acrielLabel;
    private javax.swing.JMenuItem addBoc;
    private javax.swing.JMenuItem addConsultor;
    private javax.swing.JMenuItem addEmpresa;
    private javax.swing.JMenuItem addPedido;
    private javax.swing.JMenuItem addSupervisor;
    private javax.swing.JMenuItem ajudaCustoMenuItem;
    private javax.swing.JMenu ajudaMenu;
    private javax.swing.JMenu arquivoMenu;
    private javax.swing.JPanel artePanel;
    private javax.swing.JMenuItem ativacaoMenuItem;
    private javax.swing.JLabel bemVindoLabel;
    private javax.swing.JMenu bocMenu;
    private javax.swing.JMenuItem cadastrarProdutoMenuItem;
    private javax.swing.JMenu cadastroMenu;
    private javax.swing.JMenuItem calculadoraMenuItem;
    private javax.swing.JMenu configuracaoMenu;
    private javax.swing.JMenu consultorMenu;
    private javax.swing.JLabel dataLabel;
    private javax.swing.JMenu empresaMenu;
    private javax.swing.JMenu ferramentasMenu;
    private javax.swing.JMenu financeiroMenu;
    private javax.swing.JMenu funilVendaMenu;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JPopupMenu.Separator jSeparator6;
    private javax.swing.JMenuItem listarUsuariosMenuItem;
    private javax.swing.JMenuItem logoutMenuItem;
    private javax.swing.JPanel logoutPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem novoUsuarioMenuItem;
    private javax.swing.JMenu pedidoMenu;
    private javax.swing.JMenuItem pesquisarBocMenuItem;
    private javax.swing.JMenuItem pesquisarConsultorMenuItem;
    private javax.swing.JMenuItem pesquisarEmpresaMenuItem;
    private javax.swing.JMenuItem pesquisarPedidoMenuItem;
    private javax.swing.JMenuItem pesquisarProdutoMenuItem;
    private javax.swing.JMenuItem pesquisarSupervisorMenuItem;
    private javax.swing.JMenuItem pesquisarVisitasMenuItem;
    private javax.swing.JMenuItem produtividadeMenuItem;
    private javax.swing.JMenu produtoMenu;
    private javax.swing.JMenuItem rankingDePedidosMenuItem;
    private javax.swing.JMenuItem rankingEntradaDeProdutosMenuItem;
    private javax.swing.JMenuItem relatorioAjudaCustoMenuItem;
    private javax.swing.JMenuItem relatorioAniversariantesMenuItem;
    private javax.swing.JMenuItem relatorioBocMenuItem;
    private javax.swing.JMenuItem relatorioConsultoresMenuItem;
    private javax.swing.JMenu relatorioFinanceiroMenu;
    private javax.swing.JMenuItem relatorioLinhasMenuItem;
    private javax.swing.JMenu relatorioMenu;
    private javax.swing.JMenuItem relatorioVisitasMenuItem;
    private javax.swing.JMenuItem sairMenuItem;
    private javax.swing.JPopupMenu.Separator separador1;
    private javax.swing.JMenu supervisorMenu;
    private javax.swing.JMenuItem trocarSenhaMenuItem;
    private javax.swing.JMenu usuarioMenu;
    private javax.swing.JPanel usuarioPanel;
    // End of variables declaration//GEN-END:variables

    private void carregaCabecalho() {
        Usuario usuario = loginDialog.getUsuarioSessao();
        Date agora = new Date();
        SimpleDateFormat formatador = new SimpleDateFormat("EEEE, dd/MM/yyyy");
        dataLabel.setText("Hoje é " + formatador.format(agora));
        Timestamp ultimoAcesso = usuario.getUltimoAcesso();
        if (ultimoAcesso != null) {
            bemVindoLabel.setText("Bem-vindo " + usuario.getNome()
                    + ", seu último acesso foi em: " + DateUtils.formatarTimeStamp(ultimoAcesso));
        } else {
            bemVindoLabel.setText("Bem-vindo " + usuario.getNome()
                    + ", esse é seu primeiro acesso");
        }
        logoutPanel.add(this.getLogoutLabel());
        logoutMenuItem.setAction(logoutAction);
    }

    private void carregaRodape() {
        try {
            URL url = ClassLoader.getSystemResource("br/com/tbp/resources/rodape.png");
            imagem_rodape = new JImagePanel(ImageIO.read(url));
            imagem_rodape.setFillType(JImagePanel.FillType.RESIZE);
            artePanel.add(imagem_rodape);
            artePanel.repaint();
            artePanel.validate();
        } catch (IOException ioex) {
            System.out.println(ioex.getMessage());
        }
    }

    private class LogoutAction extends AbstractAction {

        public LogoutAction(String name) {
            putValue(Action.NAME, name);
            putValue(Action.SHORT_DESCRIPTION, name);
            putValue(Action.ACCELERATOR_KEY, javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            dispose();
            loginDialog.setVisible(true);
        }
    }

    private JXHyperlink getLogoutLabel() {
        logoutAction = new LogoutAction("Realizar Logout");
        JXHyperlink logoutLink = new JXHyperlink(logoutAction);
        logoutLink.setFocusable(false);
        return logoutLink;
    }
}
